package com.hui.wanxin.web.utils;

import cn.hutool.json.JSONObject;
import com.hui.wanxin.web.entity.User;

import java.lang.reflect.Field;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: 灰灰
 * @date: 2023年04月03日 23:35
 * @ClassName: MyUtils
 * @Description: TODO
 */

public class MyUtils {


    public static class MyJson<T> {

        public  T jsonToBean(T t, String jsonData) {
            Field[] fields = t.getClass().getDeclaredFields();
            JSONObject jsonObject = new JSONObject(jsonData);

            for (Field field : fields) {
                field.setAccessible(true);
                String key = field.getName();
                Object value = jsonObject.get(key);
                try {
                    if (value != null) {
                        field.set(t, value);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return t;
        }

    }


    public static String getWeekDay() {
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DAY_OF_WEEK);
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        return weekDays[day - 1];
    }

    public static float getDatePoor(Date endDate, Date nowDate) {

        /*相差天数*/
        float nd = 1000 * 24 * 60 * 60;
        /*相差小时数*/
        float nh = 1000 * 60 * 60;
        /*相差分钟数*/
        float nm = 1000 * 60;

        // 获得两个时间的毫秒时间差异
        float diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少小时
        float day = diff / nd;

        return day;
    }

    public static boolean isEmpty(Object obj) {
        if (obj instanceof String) {
            return ((String) obj).length() == 0;
        }
        return obj == null;
    }

    public static boolean isNotEmpty(Object obj) {
        if (obj instanceof String) {
            return ((String) obj).length() != 0;
        }
        return obj != null;
    }

}
